package logic

import (
	"box-fresh/hemarpc/hemarpc"
	"box-fresh/hemarpc/internal/svc"
	"box-fresh/model/mysql"
	"context"
	"github.com/zeromicro/go-zero/core/logx"
)

type HeAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHeAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HeAddLogic {
	return &HeAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加
func (l *HeAddLogic) HeAdd(in *hemarpc.HeAddRequest) (*hemarpc.HeAddResponse, error) {
	// todo: add your logic here and delete this line

	hes := &mysql.Hes{
		Name:   in.Name,
		Weight: float64(in.Weight),
		Price:  float64(in.Price),
	}

	if err := hes.HesAdd(mysql.DB); err != nil {
		return nil, err
	}

	return &hemarpc.HeAddResponse{
		HesId: int64(hes.ID),
	}, nil
}
